﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using PaymentHelper.Methods.BaoKim.Models;
using PaymentHelper.Core.MVCUtils;

namespace PaymentHelper.Methods.BaoKim.Controllers
{
    public class BaoKimController : PaymentHelperController
    {
        protected override string SystemName
        {
            get { return "PaymentHelper.Methods.BaoKim"; }
        }

        [ChildActionOnly]
        public ActionResult Configure()
        {
            var settings = PaymentManager.Instance.LoadSettings(SystemName);

            var configModel = new ConfigModel();
            configModel.InitModel(settings);

            return View(SystemName + ".Views.BaoKim.Configure", configModel);
        }

        [HttpPost]
        [ChildActionOnly]
        public ActionResult Configure(ConfigModel model)
        {
            string viewName = SystemName + ".Views.BaoKim.Configure";

            if (!ModelState.IsValid)
                return View(viewName, model);

            var listAtrr = model.ToListAttribute();
            bool isSuccess = PaymentManager.Instance.SaveSettings(SystemName, listAtrr);

            if (isSuccess)
                ViewBag.BaoKimMessage = "Changes are saved successfully !";
            else
                ViewBag.BaoKimMessage = "Changes are saved unsuccessfully !";

            return View(viewName, model);
        }

        [ChildActionOnly]
        public ActionResult PaymentInfo()
        {
            var method = PaymentManager.Instance.LoadPaymentMethodBySystemName(SystemName);
            ViewBag.Resources = method.Descriptor.GetDefaultLanguage();

            return PartialView(SystemName + ".Views.BaoKim.PaymentInfo");
        }

        public override IList<string> ValidatePaymentInfo(FormCollection frmData)
        {
            return null;
        }
    }
}
